package com.junzhiit.nengji.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.bainaeco.framework.enums.IsDelete;
import com.junzhiit.nengji.dao.SkuItemsDAO;
import com.junzhiit.nengji.model.SkuItems;

@Repository
public class SkuItemsDAOImpl extends AbstractBaseDAO<SkuItems> implements SkuItemsDAO {

	@Override
	public List<SkuItems> findAll(String skuId, int pageNumber, int maxPageRow) {
		String sql = "select * from sku_items where is_delete=? and sku_id=? order by created_time desc";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(skuId);

		return queryForPagingList(sql.toString(), SkuItems.class, param, pageNumber, maxPageRow);
	}

	@Override
	public int getTotalCount(String skuId) {
		String sql = "select count(id) from sku_items where is_delete=? and sku_id=?";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(skuId);

		return queryForInt(sql, param);
	}

	@Override
	public int queryNameIsExit(String skuId, String standard) {
		String sql = "select count(id) from sku_items where is_delete=? and sku_id=? and standard=?";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(skuId);
		param.setString(standard);

		return queryForInt(sql, param);

	}
	
	@Override
	public List<SkuItems> getAll(String skuId){
		StringBuffer sql=new StringBuffer();
		sql.append("select * from sku_items where is_delete=? and sku_id=?");
		
		StatementParameter param=new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(skuId);
		
		return queryForList(sql.toString(),SkuItems.class,param);
	}
	
	@Override
	public int queryGoodsAboutSkuItemsCount(String skuItemsId){
		StringBuffer sql=new StringBuffer();
		sql.append("select count(*) from goods_sku_items where sku_items_id=?");
		
		StatementParameter param=new StatementParameter();
		param.setString(skuItemsId);
		
		return queryForInt(sql.toString(),param);
	}
	
	
	@Override
	public SkuItems findSkuItemsByStandard(String skuId,String standard){
		StringBuffer sql=new StringBuffer();
		sql.append(" select * from sku_items");
		sql.append(" where sku_id=?");
		sql.append(" and standard=? ");
		sql.append(" and is_delete=?");
		
		StatementParameter param=new StatementParameter();
		param.setString(skuId);
		param.setString(standard);
		param.setInt(IsDelete.NO.toIntValue());
		
		return super.query(sql.toString(),SkuItems.class, param);
	}
}
